home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / Banner Rotation.php < prev    next >
Encoding:
PHP Script  |  2001-07-02  |  2.2 KB  |  65 lines

  1.     //**************************************
  2.     //     
  3.     // Name: Banner Rotation
  4.     // Description:Automatic banner rotation
  5.     //     . Randomly selects a banner for display.
  6.     //     by Anton Olsen
  7.     // By: PHP Code Exchange
  8.     //**************************************
  9.     //     
  10.     
  11.     <?php
  12.     /* banner.phtml
  13.     Banner rotation script for PHP3 by Anton Olsen (aolsen@graphweb.com)
  14.     Please feel free to do with this script what you want, all I ask is
  15.     that if you make significant changes, please e-mail them to me.
  16.     I tried to use a number of different methods, the image functions
  17.     of PHP do not appear to understand animated GIFs and the file
  18.     handling features (fopen, fpassthru, and fclose) were causing
  19.     apache to crash on me. I settled on using passthru. Although
  20.     possibly not as portable, it appears to work faster than either
  21.     method mentioned above.
  22.     Assumptions:
  23.     You have a directory for all your banners.
  24.     All banners are GIF files.
  25.     The filenames of the banners all start with banner.
  26.     There are no other files in the directory starting with banner.
  27.     Installation:
  28.     Place this script in the banners directory.
  29.     Place all your banner*gif files in the same directory.
  30.     Add the following HTML code to your web pages :
  31.     <a href="wherever.you.want.com">
  32.     <img src="http://www.yourserver.com/bannerdir/banner.phtml" alt="Random Banner Here" border=0>
  33.     </a>
  34.     */
  35.     /* random( $max integer )
  36.     Returns a random number between 0 and $max-1;
  37.     */
  38.     function random( $max )
  39.     {
  40.     $x = rand();
  41.     $y = getrandmax();
  42.     $r = $x / $y * ($max -1 );
  43.     $r = round( $r++ );
  44.     return $r;
  45.     }
  46.     /* Read the directory, add all "banner*" files with to the array
  47.     */
  48.     $i = 0;
  49.     $d= dir(".");
  50.     while($entry=$d->read())
  51.     if (substr($entry,0,6) == "banner")
  52.     $array[$i++] = $entry;
  53.     $d->close();
  54.     /* pick a banner at random
  55.     */
  56.     $r = random( $i );
  57.     /* Send a no-cache header, and the gif type header, and output the file.
  58.     */
  59.     Header( "Pragma: no-cache" );
  60.     Header( "Expires: Monday 01-Jan-80 12:00:00 GMT" );
  61.     Header( "Content-type: image/gif");
  62.     passthru( "cat $array[$r]" );
  63.     ?>
  64.  
  65.